<?php
/**
 * filename: page.class.php
 * 2.0增加功能：支持自定义风格，自定义样式，同时支持PHP4和PHP5,
 * example:
 * 可以自定义多模式分页模式：
 * require_once('../libs/classes/page.class.php');
 * $page=new page(array('total'=>1000,'perpage'=>20));
 * echo 'mode:1<br>'.$page->show();
 * echo '<hr>mode:2<br>'.$page->show(2);
 * 开启AJAX：
 * $ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test'));
 * echo 'mode:1<br>'.$ajaxpage->show();
 * 采用继承自定义分页显示模式：
 */
class Pageclass {
    // ------------------------------------------------------------------------
	/**
	 * config ,public
	 */
	public $page_name  = "page"; // page标签，用来控制url页。比如说xxx.php?PB_page=2中的PB_page
	public $next_page  = '>'; // 下一页
	public $pre_page   = '<'; // 上一页
	public $first_page = 'First'; // 首页
	public $last_page  = 'Last'; // 尾页
	public $pre_bar    = '<<'; // 上一分页条
	public $next_bar   = '>>';// 下一分页条
	public $format_left  = '[';
	public $format_right = ']';
	public $is_ajax      = false; // 是否支持AJAX分页模式
	public $ajaxfunction = '';

	/**
	 * private
	 *
	 */ 
	private $pagebarnum = 10; // 控制记录条的个数。
	private $totalpage  = 0; // 总页数
	private $ajax_action_name = ''; // AJAX动作名
	private $nowindex   = 1; // 当前页
	private $url     = ""; // url地址头
	private $offset  = 0;
	private $total   = 0; // 总记录数
	private $perpage = 10;
    // ------------------------------------------------------------------------
	/**
	 * constructor构造函数
	 *
	 * @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']...
	 */
	public function __construct($config = array())
	{
		if( $config ){
			$this->initialize($config);
		}
	}
    // ------------------------------------------------------------------------
    // 初始化函数
	public function initialize($array = array()){
		if(is_array($array))
		{
			if(!array_key_exists('total',$array))$this->error(__FUNCTION__,'need a param of total');
			$total=intval($array['total']);
			$perpage=(array_key_exists('perpage',$array))?intval($array['perpage']):10;
			$nowindex=(array_key_exists('nowindex',$array))?intval($array['nowindex']):'';
			$url=(array_key_exists('url',$array))?$array['url']:'';
			$this->perpage = $perpage;
		}
		else
		{
			$total=$array;
			$perpage=10;
			$nowindex='';
			$url='';
			$this->perpage = 10;
		}

		if((!is_int($total))||($total<0))$this->error(__FUNCTION__,$total.' is not a positive integer!');
		if((!is_int($perpage))||($perpage<=0))$this->error(__FUNCTION__,$perpage.' is not a positive integer!');
		if(!empty($array['page_name']))$this->set('page_name',$array['page_name']);//设置pagename
		$this->_set_nowindex($nowindex);//设置当前页
		$this->_set_url($url);//设置链接地址
		$this->totalpage=ceil($total/$perpage);
		$this->totaln = $total;
		$this->offset=($this->nowindex-1)*$this->perpage;
		if(!empty($array['ajax']))$this->open_ajax($array['ajax']);//打开AJAX模式
	}
    // ------------------------------------------------------------------------
	/**
	 * 设定类中指定变量名的值，如果改变量不属于这个类，将throw一个exception
	 *
	 * @param string $var
	 * @param string $value
	 */
	public function set($var,$value)
	{
		if(in_array($var,get_object_vars($this)))
		$this->$var=$value;
		else {
			$this->error(__FUNCTION__,$var." does not belong to PB_Page!");
		}

	}
    // ------------------------------------------------------------------------
	/**
	 * 打开倒AJAX模式
	 *
	 * @param string $action 默认ajax触发的动作。
	 */
	public function open_ajax($action)
	{
		$this->is_ajax=true;
		$this->ajax_action_name=$action;
	}
    // ------------------------------------------------------------------------
	/**
	* 获取显示"下一页"的代码
	* 
	* @param string $style
	* @return string
	*/
	public function next_page($style='')
	{
		if($this->nowindex < $this->totalpage){
			return $this->_get_link($this->_get_url($this->nowindex+1),$this->next_page,$style);
		}
		return '<a class="'.$style.'">'.$this->next_page.'</a>';
	}
    // ------------------------------------------------------------------------
    // ------------------------------------------------------------------------

	/**
	 * 获取显示“首页”的代码
	 *
	 * @return string
	 */
	public function getFirstPageHTML($style='', $addAttr='')
	{
		if($this->nowindex == 1){
			return '<a class="'.$style.'"' .$addAttr. '>'.$this->first_page.'</a>';
		}
		return $this->_get_link($this->_get_url(1), $this->first_page, $style, $addAttr);
	}
	/**
	 * 获取显示“上一页”的代码
	 *
	 * @param string $style
	 * @return string
	 */
	public function getPrePageHTML($style='', $addAttr='')
	{
		if($this->nowindex > 1){
			return $this->_get_link($this->_get_url($this->nowindex-1), $this->pre_page, $style, $addAttr);
		}
		return '<a class="'.$style.'"' .$addAttr. '>'.$this->pre_page.'</a>';
	}
	/**
	* 获取显示"下一页" @20141122
	* 
	* @param string $style
	* @param string $addAttr 新增的属性
	* @return string 
	*/
	public function getNextPageHTML($style='', $addAttr='')
	{
		if($this->nowindex < $this->totalpage){
			return $this->_get_link($this->_get_url($this->nowindex+1), $this->next_page, $style, $addAttr);
		}
		return '<a class="' .$style. '"' .$addAttr. '>' . $this->next_page . '</a>';
	}
	/**
	 * 获取显示“尾页” @20141122
	 *
	 * @return string
	 */
	public function getLastPageHTML($style='', $addAttr='')
	{
		if($this->nowindex==$this->totalpage){
			return '<a class="'.$style.'"' .$addAttr. '>'.$this->last_page.'</a>';
		}
		return $this->_get_link($this->_get_url($this->totalpage), $this->last_page, $style, $addAttr);
	}
    // ------------------------------------------------------------------------

	public function next_hpage($style='')
	{
		if($this->nowindex<$this->totalpage){
			$nowindex = $this->nowindex+1;
			$this->url='news'.$_GET['nid'].'_'.$nowindex.'.html';
		} else {
			$this->url='news'.$_GET['nid'].'_'.$this->nowindex.'.html';
		}
		$nextpage = '<a href="'.$this->url.'">'.$this->next_page.'</a>';
		return $nextpage;
	}
    // ------------------------------------------------------------------------

	/**
	 * 获取显示“上一页”的代码
	 *
	 * @param string $style
	 * @return string
	 */
	public function pre_page($style='')
	{
		if($this->nowindex>1){
			return $this->_get_link($this->_get_url($this->nowindex-1),$this->pre_page,$style);
		}
		return '<a class="'.$style.'">'.$this->pre_page.'</a>';
	}
    // ------------------------------------------------------------------------

	public function pre_hpage($style='')
	{

		if($this->nowindex>1){
			$nowindex = $this->nowindex-1;
			$this->url='news'.$_GET['nid'].'_'.$nowindex.'.html';
		} else {
			$this->url='news'.$_GET['nid'].'_'.$this->nowindex.'.html';
		}
		$prepage = '<a href="'.$this->url.'">'.$this->pre_page.'</a>';
		return $prepage;
	}

    // ------------------------------------------------------------------------

	/**
	 * 获取显示“首页”的代码
	 *
	 * @return string
	 */
	public function first_page($style='')
	{
		if($this->nowindex==1){
			return '<a class="'.$style.'">'.$this->first_page.'</a>';
		}
		return $this->_get_link($this->_get_url(1),$this->first_page,$style);
	}
    // ------------------------------------------------------------------------

	public function first_hpage($style='')
	{
		$this->url='news'.$_GET['nid'].'_1.html';
		$prepage = '<a href="'.$this->url.'">'.$this->first_page.'</a>';
		return $prepage;
	}
    // ------------------------------------------------------------------------

	/**
	 * 获取显示“尾页”的代码
	 *
	 * @return string
	 */
	public function last_page($style='')
	{
		if($this->nowindex==$this->totalpage){
			return '<a class="'.$style.'">'.$this->last_page.'</a>';
		}
		return $this->_get_link($this->_get_url($this->totalpage),$this->last_page,$style);
	}
    // ------------------------------------------------------------------------

	public function last_hpage($style='')
	{
		$this->url='news'.$_GET['nid'].'_'.$this->totalpage.'.html';
		$prepage = '<a href="'.$this->url.'">'.$this->last_page.'</a>';
		return $prepage;
	}

    // ------------------------------------------------------------------------

	public function nowbar($style='', $nowindex_style='')
	{
		$plus=ceil($this->pagebarnum/2);
		if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage)$plus=($this->pagebarnum-$this->totalpage+$this->nowindex);
		$begin=$this->nowindex-$plus+1;
		$begin=($begin>=1)?$begin:1;
		$return='';
		for($i=$begin;$i<$begin+$this->pagebarnum;$i++)
		{
			if($i<=$this->totalpage){
				if($i!=$this->nowindex){
					$return .= $this->_get_text( $this->_get_link( $this->_get_url($i), $i, $style ) );
				} else {
					$return .= $this->_get_text( '<a class="'.$nowindex_style.'">'.$i.'</a>' );
				}
			} else {
				break;
			}
			$return.="\n";
		}
		unset($begin);
		return $return;
	}	
	/**
	 * 获取现在的分页按钮
	 * @param $style
	 * @param $nowIndexStyle
	 * @param $isAttrLi
	 * @return $return
	 */
	public function getNowBarLi($style='', $nowIndexStyle='', $isAttrLi=true) {
		$plus=ceil($this->pagebarnum/2);
		if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage){
			$plus = ($this->pagebarnum-$this->totalpage+$this->nowindex);
		}
		$begin  = $this->nowindex-$plus+1;
		$begin  = ($begin>=1) ? $begin : 1;
		$return = '';
		for( $i=$begin; $i<$begin+$this->pagebarnum; $i++ ) {
			if( $i<=$this->totalpage ){
				if( $isAttrLi == true ){ //a标签外有li元素
					if( $i != $this->nowindex ) {
						$return .= $this->_get_text( '<li>'.$this->_get_link( $this->_get_url($i), $i, $style ) .'</li>' );
					} else {
						$return .= $this->_get_text( '<li class="'.$nowIndexStyle.'"><a>'.$i.'</a></li>' );
					}
				} else { //a标签外没有li元素
					if( $i != $this->nowindex ) {
						$return .= $this->_get_text( $this->_get_link( $this->_get_url($i), $i, $style ) );
					} else {
						$return .= $this->_get_text( '<a class="'.$nowIndexStyle.'">'.$i.'</a>' );
					}
				}
			} else {
				break;
			}
			$return .= "\n";
		}
		unset($begin);
		return $return;
	}
    // ------------------------------------------------------------------------

	public function hnowbar($style='',$nowindex_style='')
	{
		$plus=ceil($this->pagebarnum/2);
		if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage)$plus=($this->pagebarnum-$this->totalpage+$this->nowindex);
		$begin=$this->nowindex-$plus+1;
		$begin=($begin>=1)?$begin:1;
		$return='';
		for($i=$begin;$i<$begin+$this->pagebarnum;$i++)
		{
			if($i<=$this->totalpage){
				if($i!=$this->nowindex) {
					$url='news'.$_GET['nid'].'_'.$i.'.html';
					$return.='<a href="'.$url.'" class="'.$style.'">'.$i.'</a> ';
				} else {
					$return.='<a class="'.$nowindex_style.'">'.$i.'</a> ';
				}
			}else{
				break;
			}
			$return.="\n";
		}
		unset($begin);
		return $return;
	}
    // ------------------------------------------------------------------------
	/**
	 * 获取显示跳转按钮的代码
	 *
	 * @return string
	 */
	public function select()
	{
		global $setup;
		if($this->is_ajax){
			//如果是使用AJAX模式
			$return='<select name="PB_Page_Select" onchange="'.$this->ajax_action_name.'(\''.$this->url.'\'+this.options[this.selectedIndex].value)">';
			//return '<a '.$style.' href="javascript:'.$this->ajax_action_name.'(\''.$url.'\')">'.$text.'</a>';
		}else{
			$return='<select name="PB_Page_Select" onchange="window.location=\''.$this->url.'\'+this.options[this.selectedIndex].value; if (0) this.selectedIndex=0;">';
		}
		//$return='<select name="PB_Page_Select" onchange="window.location=\''.$this->url.'\'+this.options[this.selectedIndex].value; if (0) this.selectedIndex=0;">';
		for($i=1;$i<=$this->totalpage;$i++)
		{
			if ($setup['rewrite']==1) {
				if($i==$this->nowindex){
					$return.='<option value="'.$i.'.html" selected>'.$i.'</option>';
				}else{
					$return.='<option value="'.$i.'.html">'.$i.'</option>';
				}
			} else {
				if($i==$this->nowindex){
					$return.='<option value="'.$i.'" selected>'.$i.'</option>';
				}else{
					$return.='<option value="'.$i.'">'.$i.'</option>';
				}
			}


		}
		unset($i);
		$return.='</select>';
		return $return;
	}
    // ------------------------------------------------------------------------

	/**
	 * 获取mysql 语句中limit需要的值
	 *
	 * @return string
	 */
	public function offset()
	{
		return $this->offset;
	}
    
    // ------------------------------------------------------------------------

	/**
	 * 控制分页显示风格（你可以增加相应的风格）
	 *
	 * @param int $mode
	 * @return string
	 */
	public function show($mode=10)
	{
		switch ($mode)
		{

			/**
			 * Mode1 CSS 样式说明
			 * a_num      非当前页样式
			 * a_curpage  当前页样式
			 * 其它的样式随主css的样式 
			 * 下划线之类的样式均在主css中设置
			 */ 
			//首页 上页 [1] [2] [3] [4] [5] [6] [7] 下页 未页
			case '101':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				$this->format_left  = '[';
				$this->format_right = ']';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page();

				break;

			//Bootstrap: 第一页上一页1 2 3 4 下一页最后一页
			case '102':
				$this->format_left  = '';
				$this->format_right = '';
				$this->next_page    = '下一页';
				$this->pre_page     = '上一页';
				$this->first_page   = '第一页';
				$this->last_page    = '最后一页';

				$this->pagestr  = '<ul class="pagination pagination-centered">';
				$this->pagestr .= '<li>'. $this->first_page('p_redirect') .'</li>';
				$this->pagestr .= '<li>'. $this->pre_page('p_redirect') .'</li>';
				$this->pagestr .= '<li>'. $this->getNowBarLi('p_num', 'page-active active') .'</li>';
				$this->pagestr .= '<li>'. $this->next_page('p_redirect') .'</li>';
				$this->pagestr .= '<li>'. $this->last_page('p_redirect') .'</li>';
				$this->pagestr .= '</ul>';

				return $this->pagestr;
				break;

			//带Ajax跳转： 首页 上页 1 2 3 4 5 6 7 下页 未页 第()页
			case '103':
				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				$this->format_left  = '';
				$this->format_right = '';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('p_num_1', 'p_curpage_1').' '.$this->next_page().' '.$this->last_page().' 第'.$this->select().'页';
				break;

			// 带总页数: 共7页 第一頁 上一頁 1 2 3 4 5 6 7 下一頁 最後一頁
			case '104':

				$this->next_page  = '下一页';
				$this->pre_page   = '上一页';
				$this->first_page = '第一页';
				$this->last_page  = '最后一页';
				$this->format_left  = '';
				$this->format_right = '';
				return '共'.$this->totalpage.'页 '.$this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page();
				
				break;

			//推荐使用: 第一页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 最后一页
			case '105':

				$this->next_page  = '下一页';
				$this->pre_page   = '上一页';
				$this->first_page = '第一页';
				$this->last_page  = '最后一页';
				$this->format_left  = '';
				$this->format_right = '';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page();
				
				break;

			case '201':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				$this->format_left  = '[';
				$this->format_right = ']';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page().' 第'.$this->select().'页';

				break;
			//首页 上页 [1] [2] [3] [4] [5] [6] [7] 下页 未页 共7页 / 121条记录
			case '202':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('p_num_3', 'p_curpage_3').' '.$this->next_page().' '.$this->last_page().' 共'.$this->totalpage.'页 / '.$this->totaln.'条记录';
				break;



			// 121  3/7 |‹‹‹1 2 3 4 5 6 7 ›››|	
			case '2':

				/**
				 * Mode2样式说明
				 * p_bar      整个DIV总的样式
				 * p_total    一共有多少条记录样式
				 * p_pages    当前页/总页 样式
				 * p_redirect 首页、上页样式
				 * p_num      非当前页样式
				 * p_curpage  当前页样式
				 * p_redirect 下页、未页样式
				 * p_input    文本跳转框样式
				 */ 

				$this->format_left  = '';
				$this->format_right = '';
				$this->next_page    = '&#8250;&#8250;';
				$this->pre_page     = '&#8249;&#8249;';
				$this->first_page   = '|&#8249;';
				$this->last_page    = '&#8250;|';

				$this->pagestr = '<DIV class=p_bar><A class=p_total>&nbsp;'.$this->totaln.'&nbsp;</A>';
				$this->pagestr .= '<A class=p_pages>&nbsp;'.$this->nowindex.'/'.$this->totalpage.'&nbsp;</A>';
				$this->pagestr .= $this->first_page('p_redirect');
				$this->pagestr .= $this->pre_page('p_redirect');
				$this->pagestr .= $this->nowbar('p_num', 'p_curpage');
				$this->pagestr .= $this->next_page('p_redirect');
				$this->pagestr .= $this->last_page('p_redirect');
				$this->pagestr .= '<A class=p_pages style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"><INPUT class=p_input onkeydown="if(event.keyCode==13) {window.location=\''.$this->url.'\'+this.value; return false;}" name=custompage></A></DIV>';
				return $this->pagestr;
				break;

				/**
				 *-------------------------------------------------------
				 * Mode3 CSS 样式说明
				 * a_num      非当前页样式
				 * a_curpage  当前页样式
				 * 其它的样式随主css的样式 
				 * 下划线之类的样式均在主css中设置
				 *-------------------------------------------------------
				 */ 
			//首页 上页 [1] [2] [3] [4] [5] [6] [7] 下页 未页 第页
			case '301':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				$this->format_left  = '[';
				$this->format_right = ']';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page().' 第'.$this->select().'页';

				break;
 
			// case '40':

			// 	$this->next_page  = '下页';
			// 	$this->pre_page   = '上页';
			// 	$this->first_page = '首页';
			// 	$this->last_page  = '未页';
			// 	return $this->first_page().' '.$this->pre_page().' '.$this->next_page().' '.$this->last_page().' 页次：<strong>'.$this->nowindex.'</strong>/<strong>'.$this->totalpage.' </strong><strong>'.$this->perpage.'</strong>条记录/页 转到 '.$this->select().' 页 共 <strong>'.$this->totaln.'</strong> 条记录';
			// 	break;

			//首页 上页 [1] [2] [3] [4] [5] [6] [7] 下页 未页 页次：3/7 20条记录/页 共 121 条记录
			case '400':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				return '<div id="pagination">'.$this->first_page().' '.$this->pre_page().' '.$this->nowbar('p_num_3', 'p_curpage_3').' '.$this->next_page().' '.$this->last_page().' 页次：<strong>'.$this->nowindex.'</strong>/<strong>'.$this->totalpage.' </strong><strong>'.$this->perpage.'</strong>条记录/页 共 <strong>'.$this->totaln.'</strong> 条记录</div>';
				break;	

			//带AJAX跳转: 首页 上页 下页 未页 页次：3/7 20条记录/页 转到  页 共 121 条记录
			case '401':

				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				return '<div id="pagination">'.$this->first_page().' '.$this->pre_page().' '.$this->next_page().' '.$this->last_page().' 页次：<strong>'.$this->nowindex.'</strong>/<strong>'.$this->totalpage.' </strong><strong>'.$this->perpage.'</strong>条记录/页 转到 '.$this->select().' 页 共 <strong>'.$this->totaln.'</strong> 条记录'.'</div>';

				break;

			//只数字分页: 1 2 3 4
			case '601':
				$this->format_left  = '';
				$this->format_right = '';
				return $this->nowbar('a_num', 'a_curpage');

				break;


			//jQueryMobile: 第一页 上一页 下一页 最后一页
			case '703':

				$this->next_page  = '下一页';
				$this->pre_page   = '上一页';
				$this->first_page = '第一页';
				$this->last_page  = '最后一页';
				$this->format_left  = '';
				$this->format_right = '';

				$html_class_style = '';
				$html_attribute = ' data-role="button"';
				$PAGE_HTML = '<div data-role="controlgroup" data-type="horizontal">';
				//第一页
				$PAGE_HTML .= $this->getFirstPageHTML($html_class_style, $html_attribute);
				//上一页
				$PAGE_HTML .= $this->getPrePageHTML($html_class_style, $html_attribute);
				//下一页
				$PAGE_HTML .= $this->getNextPageHTML($html_class_style, $html_attribute);
				//最后一页
				$PAGE_HTML .= $this->getLastPageHTML($html_class_style, $html_attribute);
				$PAGE_HTML .= '</div>';
				//var_dump($PAGE_HTML);exit;
				//return $this->first_page().' '.$this->pre_page() .$this->next_page().' '.$this->last_page();

				return $PAGE_HTML;
				
				break;

			// 3/7 |‹‹‹1 2 3 4 5 6 7 ›››|
			case '8':

				/**
				 *-------------------------------------------------------------------
				 * Mode2样式说明
				 *-------------------------------------------------------------------
				 * p_bar      整个DIV总的样式
				 * p_total    一共有多少条记录样式
				 * p_pages    当前页/总页 样式
				 * p_redirect 首页、上页样式
				 * p_num      非当前页样式
				 * p_curpage  当前页样式
				 * p_redirect 下页、未页样式
				 * p_input    文本跳转框样式
				 *-------------------------------------------------------------------
				 */ 

				$this->format_left  = '';
				$this->format_right = '';
				$this->next_page    = '&#8250;&#8250;';
				$this->pre_page     = '&#8249;&#8249;';
				$this->first_page   = '|&#8249;';
				$this->last_page    = '&#8250;|';

				$this->pagestr = '<div class="pagination">&nbsp;&nbsp;</A>';
				$this->pagestr .= '<A>&nbsp;'.$this->nowindex.'/'.$this->totalpage.'&nbsp;</A>';
				$this->pagestr .= $this->first_page('');
				$this->pagestr .= $this->pre_page('');
				$this->pagestr .= $this->nowbar('', 'noncepage');
				$this->pagestr .= $this->next_page('');
				$this->pagestr .= $this->last_page('');
				$this->pagestr .= '</div>';
				return $this->pagestr;

				break;

			default :
				$this->next_page  = '下页';
				$this->pre_page   = '上页';
				$this->first_page = '首页';
				$this->last_page  = '未页';
				$this->format_left  = '[';
				$this->format_right = ']';
				return $this->first_page().' '.$this->pre_page().' '.$this->nowbar('a_num', 'a_curpage').' '.$this->next_page().' '.$this->last_page();
		} //END switch
	} //END function

    // ------------------------------------------------------------------------
	// ----------------private function (私有方法)-----------------------------
	// ------------------------------------------------------------------------

	/**
     * 设置url头地址
     * @param: String $url
     * @return boolean
     */
	private function _set_url($url="")
	{
		global $setup; // 获取setup全局变量
		if(!empty($url)){
			//手动设置
			$this->url=$url.((stristr($url,'?'))?'&':'?').$this->page_name."=";
		}else{
			// 静态rewrite
			if ($setup['rewrite']==1) {
				if ($_SERVER['PHP_SELF']=="/news.php") {
					$nid = empty($_GET['nid']) ? 1 : $_GET['nid'];
					$this->url = 'news'.$nid.'_';
				} elseif ($_SERVER['PHP_SELF']=="/product.php") {
					$pid = empty($_GET['pid']) ? 1 : $_GET['pid'];
					$this->url = 'product'.$pid.'_';
				} elseif ($_SERVER['PHP_SELF']=="/case.php") {
					$cid = empty($_GET['cid']) ? 1 : $_GET['cid'];
					$this->url = 'case'.$cid.'_';
				}

			} else { // 动态
				//自动获取
				if(empty($_SERVER['QUERY_STRING'])){
					//不存在QUERY_STRING时
					$this->url=$_SERVER['REQUEST_URI']."?".$this->page_name."=";
				}else{
					//
					if(stristr($_SERVER['QUERY_STRING'],$this->page_name.'=')){
						//地址存在页面参数
						$this->url=str_replace($this->page_name.'='.$this->nowindex,'',$_SERVER['REQUEST_URI']);
						$last=$this->url[strlen($this->url)-1];
						if($last=='?'||$last=='&'){
							$this->url.=$this->page_name."=";
						}else{
							$this->url.='&'.$setup['rewrite'].$this->page_name."=";
						}
					}else{
						//
						$this->url=$_SERVER['REQUEST_URI'].'&'.$this->page_name.'=';
					}//end if
				}//end if
			}
		}//end if
	} //END function _set_url()


    // ------------------------------------------------------------------------

	/**
     * 设置当前页面
     *
     */
	private function _set_nowindex($nowindex)
	{
		if(empty($nowindex)){
			//系统获取

			if(isset($_GET[$this->page_name])){
				$this->nowindex=intval($_GET[$this->page_name]);
			}
		}else{
			//手动设置
			$this->nowindex=intval($nowindex);
		}
	}
    // ------------------------------------------------------------------------

	/**
     * 为指定的页面返回地址值
     *
     * @param int $pageno
     * @return string $url
     */
	private function _get_url($pageno=1)
	{
		global $setup;
		if ($setup['rewrite'] == 1) {
			return $this->url.$pageno.'.html';
		} else {
			return $this->url.$pageno;
		}
	}
    // ------------------------------------------------------------------------

	/**
     * 获取分页显示文字，比如说默认情况下_get_text('<a href="">1</a>')将返回[<a href="">1</a>]
     *
     * @param String $str
     * @return string $url
     */ 
	private function _get_text($str)
	{
		return $this->format_left.$str.$this->format_right;
	}
    // ------------------------------------------------------------------------

	/**
     * 获取链接地址
     * @param string $url 链接地址
     * @param string $text 链接的内容
     * @param string $style 样式
     * @param string $addAttr 新增加的属性 如增加data-role="button"
     * @return 如<a class="ui-link" href="admin123.php?page=8" data-role="button">下一页</a>
     */
	private function _get_link($url, $text, $style='', $addAttr=''){
		$style=(empty($style))?'':'class="'.$style.'"';
		if($this->is_ajax){
			//如果是使用AJAX模式
			return '<a '. $style . $addAttr . ' href="javascript:'.$this->ajax_action_name.'(\''.$url.'\')">'.$text.'</a>';
		}else{
			return '<a '. $style . $addAttr . ' href="'.$url.'">'.$text.'</a>';
			//return '<a '.$style.' href="'.$url.'">'.$text.'</a>';
		}
	}
    // ------------------------------------------------------------------------
	/**
     * 出错处理方式
     */
	private function error($function,$errormsg)
	{
		die('Error in file <b>'.__FILE__.'</b> ,Function <b>'.$function.'()</b> :'.$errormsg);
	}
    // ------------------------------------------------------------------------
}   // CLASS END
